<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<html>
<form role="form" class="form-validation" id="fm">
	<input type="hidden" name="complainId" id=complainId value="${param.complainId }">
		<div class="row">
			<div class="col-md-4 form-group">
				<label id="goalName"></label> <span id="name"></span>
			</div>
			<div class="col-md-4 form-group">
				<label>目标类型：</label> <span id="goalType"></span>
			</div>
			<div class="col-md-4 form-group">
				<label>投诉建议人:</label> <span id="complainsUserName"></span>
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="row">
			<div class="col-md-8 form-group">
				<label>投诉建议内容:</label> <span id="content"></span>
			</div>
			<div class="col-md-4 form-group">
				<label>投诉建议图片:</label> <img alt="" src="" id="advicePhoto" style="width: 40px;height: 40px;">
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="row" id="shop">
			<div class="col-md-2">
				<label>回复内容:</label> 
			</div>
			<div class="col-md-10">
				<textarea style="width: 405px;" id="respondContent" disabled="disabled"></textarea>
			</div>
		</div>
		<div class="clearfix"></div>
		<div class="row" id="admin">
			<div class="col-md-2">
				<label>仲裁结果:</label> 
			</div>
			<div class="col-md-10">
				<textarea style="width: 405px;" id="finalResult" maxlength="500"></textarea>
			</div>
		</div>
		<div class="form-group text-center" id="btnDiv">
			
		</div>
	</form>

	<script type="text/javascript">
		$(function(){
        	 $.ajax({
				 type:"POST",
		         url: "<%=path %>/manager/lookComplains?complainId=${param.complainId}",
		         success: function(data,status,xhr){
		        	if(data.complainsInfo.goalType==0){
		        		$("#goalName").html("商家名称");
		        		$("#name").html(data.name);
		        		$("#goalType").html("商家");
		        	}else if(data.complainsInfo.goalType==1){
		        		$("#goalName").html("订单编号");
		        		$("#name").html(data.name);
		        		$("#goalType").html("订单");
		        	}
		        	$('#complainsUserName').html(data.userNme);
		        	$('#content').html(data.complainsInfo.comPlainContent);
		        	var srcPhoto = "<%=path %>/manager/getApplyPhoto?photoUrl="+data.complainsInfo.complainAnnex;
		        	var onclickFunction = "showImg('"+srcPhoto+"')";
		        	$("#advicePhoto").attr("onclick",onclickFunction);
		        	$('#advicePhoto').attr("src",srcPhoto);
		        	if(data.complainsInfo.complainStatus==0){
		        		$("#admin").hide();
		        		$("#shop").hide();
		        		$("#btnDiv").html('<br><button class="btn btn-md btn-primary" type="button" onclick="closeAdmin()"> 关闭 </button>&nbsp;&nbsp;&nbsp;&nbsp;');
		        	}else if(data.complainsInfo.complainStatus==3||data.complainsInfo.complainStatus==1||data.complainsInfo.complainStatus==2){
		        		$("#respondContent").html(data.complainsInfo.respondContent);
		        		$("#btnDiv").html('<button class="btn btn-md btn-primary" type="button" onclick="arbitrament()"> 仲裁 </button>&nbsp;&nbsp;&nbsp;&nbsp;');
		        	}else if(data.complainsInfo.complainStatus==4){
		        		$("#respondContent").html(data.complainsInfo.respondContent);
		        		$("#finalResult").html(data.complainsInfo.finalResult);
		        		$("#finalResult").attr("disabled","disabled");
		        		$("#btnDiv").html('<br><button class="btn btn-md btn-primary" type="button" onclick="closeAdmin()"> 关闭 </button>&nbsp;&nbsp;&nbsp;&nbsp;');
		        	}
		         }
			})
		})
		function arbitrament(){
			var finalResult = $("#finalResult").val();
			if(finalResult==null||finalResult==''){
				swal({ 
		 			  title: "仲裁内容不能为空", 
		 			  text: "仲裁内容不能为空", 
		 			  type: "waring",
		 			});
			}else{
	    	$.ajax({
				 type:"POST",
		         url: "<%=path %>/manager/arbitramentComplains?complainId=${param.complainId}",
		         data: {"finalResult":finalResult},
		         dataType: 'json',
		         success: function(data,status,xhr){
		        	 if(data==1){
		        		 swal({ 
				   			  title: "提交成功", 
				   			  text: "仲裁成功", 
				   			  type: "success",
				   			},function(){
				        		 $("#tabId").bootstrapTable('refresh');
				        		 $('#myModal').modal('hide')
				   			});
	        	    }else{
	        	    	swal({ 
	  		 			  title: "仲裁失败", 
	  		 			  text: "失败", 
	  		 			  type: "error",
	  		 			});
	        	    }
		         }
		       });
	    	}
		};
		function closeAdmin(){
			$('#myModal').modal('hide');
		};
		function showImg(url){
			var wight = '';
			var height = '';
			var img = document.getElementById("advicePhoto");
			getImgNaturalDimensions(img, function(dimensions){
				wight = dimensions.w;
				height = dimensions.h;
			});
			console.log("wight----"+wight)
			var img1 = "<img id='showImg'  src='" + url + "' />";  
			layer.open({  
			    type: 1,  
			    shade: false,  
			    title: false, //不显示标题  img.width +img.height+
			    area: [wight , height], 
			    offset: ["150px", "450px"],
			    move:'img',
			    content: img1, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响  
			    cancel: function () {  
			    	layer.closeAll(); 
			    }  
			});  
		};
		//获取照片宽高
		function getImgNaturalDimensions(oImg, callback) {
			　　var nWidth, nHeight;
			　　if (!oImg.naturalWidth) { // 现代浏览器

			　　　　nWidth = oImg.naturalWidth;
			　　　　nHeight = oImg.naturalHeight;
			console.log("nWidth----"+nWidth)
				if(nWidth>200){
					nWidth = 200;
				}
				if(nHeight>200){
					nHeight = 200;
				}
			　　　　callback({w: nWidth, h:nHeight});

			　　} else { // IE6/7/8
			　　　　var nImg = new Image();

			        nImg.onload = function() {
			             var nWidth = nImg.width,
			                 nHeight = nImg.height;
			           callback({w: nWidth, h:nHeight});
			　　　　}
			　　　　nImg.src = oImg.src;
			　　}
			}
	
		</script>
</html>